<?php

/**
 * default Components.
 *
 * @package    social
 * @subpackage default
 * @author     Your name here
 * @version    SVN: $Id: Components.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class zestawienieComponents extends sfComponents
{


  /**
   * Search form
   * @param sfRequest $request A request object
   */
  public function executeMenu(sfWebRequest $request)
  {
      $this->user = $this->getUser()->getGuardUser();
       $this->messages = Doctrine::getTable('sfSocialMessageRcpt')->getUserMessages($this->user);
    $this->unread = Doctrine::getTable('sfSocialMessageRcpt')->countUnreadMessages($this->user);
  }
  
  public function executeMenuTerapeuta(sfWebRequest $request)
  {
      $this->user = $this->getUser()->getGuardUser();
       $this->messages = Doctrine::getTable('sfSocialMessageRcpt')->getUserMessages($this->user);
    $this->unread = Doctrine::getTable('sfSocialMessageRcpt')->countUnreadMessages($this->user);
  }
  
  /**
   * Zwraca grupę do jakiej nalezy uzytkownik
   * @param sfWebRequest $request 
   */
  public function executeGetUsersGroupByUserId(sfWebRequest $request)
  {  
    //$this->user = $this->getUser()->getGuardUser();
    $this->users_groups = $this->groups;  
    /*$this->users_group = Doctrine_Core::getTable('sfSocialGroupUser')
        ->createQuery('g')
        ->select('g.*')
        ->where('g.user_id = ?', $this->user_id)
        ->orderBy('g.created_at DESC')  
        ->execute();*/
    
  }
  
    /**
   * Zwraca różnice pomiedzy pierwsza a ostatnim wynikiem dla danego id_rozgrywki
   * @param sfWebRequest $request 
   */
  public function executeGetAllDatesInARow(sfWebRequest $request)
  {  
    
    if ($this->user_id == null):
        $userid = $this->getUser()->getGuardUser()->getId();
    else:
        $userid = $this->user_id; 
    endif;  
           
    $game_results = Doctrine_Core::getTable('GameResult')
      ->createQuery('a')
      ->where('a.user_id = ?', $userid)
      ->addWhere('a.games_id = ?', $this->gameid)
      ->addWhere('a.rozgrywka_id = ?', $this->rozgrywka_id)
      ->orderBy('a.end_date ASC')
      ->execute();
    
    $this->dates = array();
    foreach ($game_results as $result):
        $this->dates[] = array('start' => $result->start_date, 'end' => $result->end_date);
    endforeach;
    
    
    
  }
  
}